package com.mdd.admin.controller.goods;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.goods.ILimitedTimeGoodsService;
import com.mdd.admin.validate.goods.LimitedTimeGoodsParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.goods.LimitedTimeGoodsListVo;
import com.mdd.admin.vo.goods.LimitedTimeGoodsDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 限时商品管理
 */
@RestController
@RequestMapping("api/limited")
public class LimitedTimeGoodsController {

    @Resource
    ILimitedTimeGoodsService iLimitedTimeGoodsService;

    /**
     * 限时商品列表
     *
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<LimitedTimeGoodsListVo> list = iLimitedTimeGoodsService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 限时商品详情
     *
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        LimitedTimeGoodsDetailVo detail = iLimitedTimeGoodsService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 限时商品新增
     *
     * @param limitedTimeGoodsParam 参数
     * @return Object
     */
    @Log(title = "限时商品新增")
    @PostMapping("/add")
    public Object add(@RequestBody LimitedTimeGoodsParam limitedTimeGoodsParam) {
        iLimitedTimeGoodsService.add(limitedTimeGoodsParam);
        return AjaxResult.success();
    }

    /**
     * 限时商品编辑
     *
     * @param limitedTimeGoodsParam 参数
     * @return Object
     */
    @Log(title = "限时商品编辑")
    @PostMapping("/edit")
    public Object edit(@RequestBody LimitedTimeGoodsParam limitedTimeGoodsParam) {
        iLimitedTimeGoodsService.edit(limitedTimeGoodsParam);
        return AjaxResult.success();
    }

    /**
     * 限时商品删除
     *
     * @param limitedTimeGoodsParam 参数
     * @return Object
     */
    @Log(title = "限时商品删除")
    @PostMapping("/del")
    public Object del(@RequestBody LimitedTimeGoodsParam limitedTimeGoodsParam) {
        iLimitedTimeGoodsService.del(limitedTimeGoodsParam.getId());
        return AjaxResult.success();
    }

}
